$(document).ready(function() {
   $.getJSON("/getdatacenter/", function(data,textStatus){
      var datalist=[];
      $.each(data, function(i, item){
             datalist[i]=item.fields.name
           });
      $("#datacenter").autocomplete({
         source:datalist
       });
    });
  $('#datacenter').change(function(){
    var datacenter = $('#datacenter').val();
    if (datacenter)
     {
        $.getJSON("/getdata/?datacenter="+datacenter, function(data,textStatus){
            var content='';
            $.each(data, function(i, item){
                content+='<option value='+item.pk+'>'+item.fields.name+'</option>'
            });
            $('#machineroom').html(content)
        });
     }
    else
     {
       var content='<option>请选择</option>';
        $('#machineroom').html(content)
     }
   });
})
